package honeypot.wljkzxt.action;

import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.general.DefaultPieDataset;

import com.opensymphony.xwork2.ActionSupport;

public class NetChartAction extends ActionSupport {
	
	public String execute() throws Exception
	{
		
		DefaultPieDataset dataset= new DefaultPieDataset();
        dataset.setValue("技术人员", 25);
		dataset.setValue("后勤人员", 12);
		dataset.setValue("销售人员", 26);
  JFreeChart chart=ChartFactory.createPieChart3D("企业人员饼图", dataset, true, false, false);
        chart.getTitle().setFont(new Font("宋体",Font.BOLD,15));
		PiePlot3D plot=(PiePlot3D)chart.getPlot();
		plot.setLabelGenerator(new StandardPieSectionLabelGenerator( 
				"{0}={1}({2})", NumberFormat.getNumberInstance(), 
				new DecimalFormat("0.00%"))); 
		plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator( 
		"{0}={1}({2})",NumberFormat.getNumberInstance(), 
		new DecimalFormat("0.00%"))); 
		plot.setLabelFont(new Font("宋体",Font.BOLD,10));
		plot.setBackgroundPaint(Color.WHITE);
		plot.setBackgroundImageAlpha(0.65f);
		plot.setForegroundAlpha(0.65f); 
		plot.setCircular(false, false); 

		LegendTitle legend=chart.getLegend();
		legend.setItemFont(new Font("宋体",Font.BOLD,10));
		
		HttpServletResponse response = ServletActionContext.getResponse();
		try {
			ChartUtilities.writeChartAsJPEG(response.getOutputStream(), chart,
					500, 300);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
